package com.keldian.myqq.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.keldian.myqq.R;
import com.keldian.myqq.entity.UserInfoWrapper;
import com.keldian.myqq.smartImageView.SmartImageView;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 15-11-18.
 */
public class MyNewsAdapter extends BaseAdapter {

    private List<UserInfoWrapper.UserInfo> list = new ArrayList<UserInfoWrapper.UserInfo>();

    private Context context;

    public MyNewsAdapter(Context context, List<UserInfoWrapper.UserInfo> list) {
        this.list = list;
        this.context = context;
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.tab_listview_news, null);
            ViewUtils.inject(viewHolder, convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        UserInfoWrapper.UserInfo userInfo = list.get(position);
        viewHolder.name.setText(userInfo.getName());
        viewHolder.signature.setText(userInfo.getSignature());
        viewHolder.smartImageView.setTag(userInfo.getHead());
        if (viewHolder.smartImageView.getTag().equals(userInfo.getHead())) {
            viewHolder.smartImageView.setImageUrl(userInfo.getHead(),
                    R.drawable.image1, R.drawable.touxiang);
        }
        return convertView;
    }

    public class ViewHolder {
        @ViewInject(R.id.name)
        TextView name;
        @ViewInject(R.id.signature)
        TextView signature;
        @ViewInject(R.id.smartImageView)
        SmartImageView smartImageView;
    }
}
